﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Services
Imports System.IO

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class MCO
    Inherits System.Web.Services.WebService
    '--------------LOGIN: CODE, PASS, MACHINE-------------------: FILTER BY MACHINE ID
    <WebMethod()> _
   <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function _Function01_(ByVal Para01 As String, ByVal Para02 As String, ByVal Para03 As String) As String
        Dim connect As New Connection()
        Try
            Dim str As String = "Select * from _OUSR with(nolock) where UserCode='" + Para01 + "' and Password='" + Para02 + "'"
            Dim ds As New DataSet
            ds = connect.ObjectGetAll_Query_SAP(str)
            If ds.Tables.Count = 0 Then
                Return "User & Password does not match!"
            Else
                If ds.Tables(0).Rows.Count = 0 Then
                    Return "User & Password does not match!"
                Else
                    If ds.Tables(0).Rows(0)("Status") <> "O" Then
                        Return "This user is inactive!"
                    Else
                        Return ""
                        'If ds.Tables(0).Rows(0)("MachineID").ToString <> Para03 Then
                        '    Return "This machine is not registered for this user!"
                        'Else
                        '    Return ""
                        'End If
                    End If
                End If
            End If
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------TODAY ACTIVITY: USER CODE, DATE--------------
    <WebMethod()> _
    Public Function _Function02_(ByVal Para01 As String, ByVal Para02 As String) As String
        Dim connect As New Connection()
        Try
            Dim str As String = "select ClgCode,CardCode, Notes,Details from OCLG"
            Return connect.ObjectGetAll_Query_SAP_JSON(str)
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------LIST OF LEADS: USER CODE---------------------
    <WebMethod()> _
    Public Function _Function03_(ByVal Para01 As String) As String
        Dim connect As New Connection()
        Try
            Dim str As String = "select CardCode, CardName,Address from OCRD where CardType<>'S'"
            Return connect.ObjectGetAll_Query_SAP_JSON(str)
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------Create/UPDATE LEAD: USER CODE---------------------
    <WebMethod()> _
    Public Function _Function04_(ByVal Para01 As String, ByVal Para02 As String, ByVal Para03 As String, _
                                 ByVal Para04 As String, ByVal Para05 As String, ByVal Para06 As String, _
                                 ByVal Para07 As String, ByVal Para08 As String) As String
        Dim connect As New Connection()
        Try
            Dim Series As String = ""
            Series = connect.ObjectGetAll_Query_SAP("select top(1) Series from NNM1 where ObjectCode='2' and DocSubType='C' and IsManual='N'").Tables(0).Rows(0).Item("Series").ToString

            Dim dtOCRD As DataTable = oXML.BuildTable("OCRD", "CardCode;CardName;CardType;Series;U_UserCode")
            dtOCRD.Rows.Add(Para08, Para02, "L", Series, Para01)

            Dim ds As New DataSet
            ds.Tables.Add(dtOCRD.Copy)

            Dim xmlstring As String
            xmlstring = oXML.ToXMLStringFromDS("2", ds)

            Dim ret As String = ""
            ret = oXML.CreateMarketingDocument(xmlstring, "2", Para08)

            Return ret
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------Create/UPDATE ACTIVITY: USER CODE---------------------
    <WebMethod()> _
    Public Function _Function05_(ByVal Para01 As String, ByVal Para02 As String, ByVal Para03 As String, _
                                 ByVal Para04 As String, ByVal Para05 As String, ByVal Para06 As String, _
                                 ByVal Para07 As String) As String
        Dim connect As New Connection()
        Try
            If Para07 <> "" Then
                'update
            Else
                'create
            End If
            Return ""
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '-------------- ACTIVITY TYPE: DONE------------------------
    <WebMethod()> _
    Public Function _Function06_() As String
        Dim connect As New Connection()
        Try
            Dim str As String = "select Code,Name from OCLT"
            Return connect.ObjectGetAll_Query_SAP_JSON(str)
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '-------------- OPPORTUNITY LIST: DONE------------------------
    <WebMethod()> _
    Public Function _Function07_(ByVal Para01 As String, ByVal Para02 As Integer) As String
        Dim connect As New Connection()
        Try
            Dim str As String = "select OpprId,CardCode,MaxSumLoc from OOPR"
            Return connect.ObjectGetAll_Query_SAP_JSON(str)
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------Create/UPDATE OPPORTUNITY: USER CODE---------------------
    <WebMethod()> _
    Public Function _Function08_(ByVal Para01 As String, ByVal Para02 As String, ByVal Para03 As String, ByVal Para04 As String, _
                                 ByVal Para05 As String, ByVal Para06 As String, ByVal Para07 As String, ByVal Para08 As String, _
                                 ByVal Para09 As String) As String
        Dim connect As New Connection()
        Try
            If Para09 <> "" Then
                'update
            Else
                'create
            End If
            Return ""
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '-------------- SALES STAGE: DONE------------------------
    <WebMethod()> _
    Public Function _Function09_() As String
        Dim connect As New Connection()
        Try
            Dim str As String = "select Num,Descript from OOST"
            Return connect.ObjectGetAll_Query_SAP_JSON(str)
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------REPORT LIST: USER CODE-------------------: FILTER & SETUP BY USER/MOBILE
    <WebMethod()> _
    Public Function _Function10_(ByVal Para01 As String) As String
        Dim connect As New Connection()
        Try
            Dim str As String = ""
            str = str + " SELECT T0.ReportName REPORTID,MenuName REPORTNAME FROM _ORPT T0 WITH(NOLOCK)"
            str = str + " LEFT JOIN _ORP1 T1 WITH(NOLOCK) ON T0.ReportName=T1.ReportName WHERE T1.ID IS NULL"

            Return connect.ObjectGetAll_Query_SAP_JSON(str)

        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
    '--------------REPORT RUN: USERCODE, REPORTID-------------------DONE
    <WebMethod()> _
    Public Function _Function11_(ByVal Para01 As String, ByVal Para02 As String) As String
        Dim connect As New Connection()
        Try
            Dim str As String = ""
            str = str + " SELECT querystr FROM _ORPT T0 WITH(NOLOCK) where reportname='" + Para02 + "'  "
            Dim ds As DataSet = connect.ObjectGetAll_Query_SAP(str)
            If ds.Tables.Count > 0 Then
                If ds.Tables(0).Rows.Count > 0 Then
                    Return connect.ObjectGetAll_Query_SAP_JSON(ds.Tables(0).Rows(0)(0).ToString)
                Else
                    Return "NO DATA"
                End If
            Else
                Return "NO DATA"
            End If

        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
   

   
End Class